作业1、给定一个列表, 根据grade来排序
classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
作业二、通过filter语句来筛选出Grade为A的同学

作业三、通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda)

作业四、使用递归函数重构斐波那契函数
f(n) = f(n-1) + f(n-2)


# 1.根据grade排序
classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]

classes1 = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
print("classes的类型为：", type(classes))

classes.sort(key=lambda x: x['grade'])
for cl in classes:
    print(cl)
print("classes的类型为：", type(classes))


# 2.通过filter语句来筛选出Grade为A的同学

f = filter(lambda x: x["grade"] == "A", classes)

print(list(f))


# 3.通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda)

# 用了lmbda 增加classes1
m1 = map(lambda x: x["age"] + 1, classes1)

print("classes1年龄加1岁：", list(m1))

# 不用lmbda，classes加一岁

def add(n):
    n["age"] = n['age'] + 1
    return n

m = map(add, classes)
print("不用lambda：", list(m))

# 4.使用递归函数重构斐波那契函数


def fib(n):
    if n <= 1:
        return n
    else:
        return fib(n - 1) + fib(n - 2)

print(fib(15))